Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
bookmenu.c
Go to the documentation of this file.
1class 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
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}
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()
const int IDC_BOOK_VIEWER_PREV
Definition constants.c:154
const int IDC_BOOK_VIEWER_NEXT
Definition constants.c:155
const int IDC_CANCEL
Definition constants.c:136
Icon x
Icon y
void Close()