DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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;
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
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}
Icon x
Icon y
void Close()
proto native WorkspaceWidget GetWorkspace()
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
protected TextWidget m_page
Definition BookMenu.c:5
protected float m_content_total_height
Definition BookMenu.c:8
protected HtmlWidget m_content
Definition BookMenu.c:6
protected TextWidget m_title
Definition BookMenu.c:4
protected float m_page_height
Definition BookMenu.c:7
protected float m_content_pos
Definition BookMenu.c:9
protected TextWidget m_author
Definition BookMenu.c:3
override Widget Init()
Definition BookMenu.c:11
void ReadBook(InventoryItem book)
Definition BookMenu.c:24
void NextPrevPage(bool next)
Definition BookMenu.c:54
override bool OnClick(Widget w, int x, int y, int button)
Definition BookMenu.c:34
proto string ToString()
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:132
const int IDC_BOOK_VIEWER_NEXT
Definition constants.c:133
const int IDC_CANCEL
Definition constants.c:116
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.