Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
bookmenu.c
Go to the documentation of this file.
1 class BookMenu extends UIScriptedMenu
2 {
3  protected TextWidget m_author;
4  protected TextWidget m_title;
5  protected TextWidget m_page;
6  protected HtmlWidget m_content;
7  protected float m_page_height;
8  protected float m_content_total_height;
9  protected float m_content_pos;
10 
11  override Widget Init()
12  {
13  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_book.layout");
14  Class.CastTo(m_content, layoutRoot.FindAnyWidget("HtmlWidget"));
15  Class.CastTo(m_author, layoutRoot.FindAnyWidget("Author"));
16  Class.CastTo(m_title, layoutRoot.FindAnyWidget("Title"));
17  Class.CastTo(m_page, layoutRoot.FindAnyWidget("Page"));
18 
19  float width;
20  m_content.GetScreenSize(width, m_page_height);
21  return layoutRoot;
22  }
23 
24  void ReadBook(InventoryItem book)
25  {
26  m_content.LoadFile( book.ConfigGetString("file") );
27  m_author.SetText( book.ConfigGetString("author") );
28  m_title.SetText( book.ConfigGetString("title") );
29  m_content_total_height = m_content.GetContentHeight();
30  m_content_pos = 0;
31  NextPrevPage(false);
32  }
33 
34  override bool OnClick(Widget w, int x, int y, int button)
35  {
36  super.OnClick(w, x, y, button);
37 
38  switch (w.GetUserID())
39  {
41  NextPrevPage(false);
42  return true;
44  NextPrevPage(true);
45  return true;
46  case IDC_CANCEL:
47  Close();
48  return true;
49  }
50 
51  return false;
52  }
53 
54  void NextPrevPage(bool next)
55  {
56  if (next)
57  {
58  m_content_pos = m_content_pos + m_page_height;
59  }
60  else
61  {
62  m_content_pos = m_content_pos - m_page_height;
63  }
64 
65  float maxOffset = 0;
66  if (m_content_total_height > m_page_height)
67  {
68  maxOffset = m_content_total_height - m_page_height;
69  }
70 
71  if (m_content_pos < 0)
72  {
73  m_content_pos = 0;
74  }
75 
76  if (m_content_pos > maxOffset)
77  {
78  m_content_pos = maxOffset;
79  }
80 
81  m_content.SetContentOffset(m_content_pos, true);
82 
83  float pagesTotal = Math.Ceil(m_content_total_height / m_page_height);
84  float currPage = Math.Round(m_content_pos / m_page_height) + 1;
85 
86  m_page.SetText( currPage.ToString() + " / " + pagesTotal.ToString() );
87  }
88 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
IDC_CANCEL
const int IDC_CANCEL
Definition: constants.c:128
Close
void Close()
y
Icon y
InventoryItem
Definition: itembase.c:13
IDC_BOOK_VIEWER_PREV
const int IDC_BOOK_VIEWER_PREV
Definition: constants.c:144
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
x
Icon x
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
IDC_BOOK_VIEWER_NEXT
const int IDC_BOOK_VIEWER_NEXT
Definition: constants.c:145