DayZ 1.24
Loading...
Searching...
No Matches
BookMenu.c
Go to the documentation of this file.
1class BookMenu extends UIScriptedMenu
2{
4 protected TextWidget m_title;
5 protected TextWidget m_page;
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
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 m_content_pos = m_content_pos + m_page_height;
58 else
59 m_content_pos = m_content_pos - m_page_height;
60
61 float maxOffset = 0;
62 if (m_content_total_height > m_page_height)
63 maxOffset = m_content_total_height - m_page_height;
64
65 if (m_content_pos < 0)
66 m_content_pos = 0;
67
68 if (m_content_pos > maxOffset)
69 m_content_pos = maxOffset;
70
71 m_content.SetContentOffset(m_content_pos, true);
72
73 float pagesTotal = Math.Ceil(m_content_total_height / m_page_height);
74 float currPage = Math.Round(m_content_pos / m_page_height) + 1;
75
76 m_page.SetText(currPage.ToString() + " / " + pagesTotal.ToString());
77 }
78}
Icon x
Icon y
void Close()
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
TextWidget m_title
Definition BookMenu.c:4
void ReadBook(InventoryItem book)
Definition BookMenu.c:24
float m_content_total_height
Definition BookMenu.c:8
float m_content_pos
Definition BookMenu.c:9
override Widget Init()
Definition BookMenu.c:11
override bool OnClick(Widget w, int x, int y, int button)
Definition BookMenu.c:34
TextWidget m_author
Definition BookMenu.c:3
HtmlWidget m_content
Definition BookMenu.c:6
float m_page_height
Definition BookMenu.c:7
void NextPrevPage(bool next)
Definition BookMenu.c:54
TextWidget m_page
Definition BookMenu.c:5
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Ceil(float f)
Returns ceil of value.
const int IDC_BOOK_VIEWER_PREV
Definition constants.c:144
const int IDC_BOOK_VIEWER_NEXT
Definition constants.c:145
const int IDC_CANCEL
Definition constants.c:128