]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc
Merge branch 'master' into terencehill/menu_listbox_changes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_media_screenshot_viewer.qc
1 #ifndef DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
2 #define DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
3 #include "dialog.qc"
4 CLASS(XonoticScreenshotViewerDialog, XonoticDialog)
5         METHOD(XonoticScreenshotViewerDialog, fill, void(entity))
6         METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float))
7         METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string))
8         METHOD(XonoticScreenshotViewerDialog, close, void(entity))
9         ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
10         ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer")
11         ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
12         ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
13         ATTRIB(XonoticScreenshotViewerDialog, columns, float, 4)
14         ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
15         ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
16         ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
17         ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
18         ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
19 ENDCLASS(XonoticScreenshotViewerDialog)
20 #endif
21
22 #ifdef IMPLEMENTATION
23 float music_playlist_index_backup;
24 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
25 {
26         // disable music as it can lag depending on image loading time
27         if(!cvar("menu_screenshotviewer_enablemusic"))
28         if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
29         {
30                 // pause music
31                 if(cvar("music_playlist_index") != -1)
32                 {
33                         music_playlist_index_backup = cvar("music_playlist_index");
34                         cvar_set("music_playlist_sampleposition0", "0");
35                         cvar_set("music_playlist_index", "999");
36                 }
37                 else
38                         localcmd("\ncd pause\n");
39         }
40
41         if (me.currentScrPath == scrImage)
42                 return;
43         if (me.currentScrPath)
44                 strunzone(me.currentScrPath);
45         me.currentScrPath = strzone(scrImage);
46         me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
47         me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
48 }
49 void prevScreenshot_Click(entity btn, entity me)
50 {
51         me.scrList.goScreenshot(me.scrList, -1);
52 }
53 void nextScreenshot_Click(entity btn, entity me)
54 {
55         me.scrList.goScreenshot(me.scrList, +1);
56 }
57 void increaseZoom_Click(entity btn, entity me)
58 {
59         me.screenshotImage.setZoom(me.screenshotImage, -2, false);
60 }
61 void decreaseZoom_Click(entity btn, entity me)
62 {
63         me.screenshotImage.setZoom(me.screenshotImage, -1/2, false);
64 }
65 void resetZoom_Click(entity btn, entity me)
66 {
67         me.screenshotImage.setZoom(me.screenshotImage, 0, false);
68 }
69 void toggleSlideShow_Click(entity btn, entity me)
70 {
71         if (me.slideShowButton.forcePressed)
72         {
73                 me.scrList.stopSlideShow(me.scrList);
74                 me.slideShowButton.forcePressed = 0;
75         }
76         else
77         {
78                 me.scrList.startSlideShow(me.scrList);
79                 me.slideShowButton.forcePressed = 1;
80         }
81 }
82 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
83 {
84         switch(key)
85         {
86                 case K_KP_LEFTARROW:
87                 case K_LEFTARROW:
88                         me.scrList.goScreenshot(me.scrList, -1);
89                         return 1;
90                 case K_KP_RIGHTARROW:
91                 case K_RIGHTARROW:
92                         me.scrList.goScreenshot(me.scrList, +1);
93                         return 1;
94                 case K_KP_ENTER:
95                 case K_ENTER:
96                 case K_SPACE:
97                         // we cannot use SPACE/ENTER directly, as in a dialog they are needed
98                         // to press buttons while browsing with only the keyboard
99                         if (shift & S_CTRL)
100                         {
101                                 toggleSlideShow_Click(world, me);
102                                 return 1;
103                         }
104                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
105                 default:
106                         if (key == K_MWHEELUP || ascii == '+')
107                         {
108                                 me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
109                                 return 1;
110                         }
111                         else if (key == K_MWHEELDOWN || ascii == '-')
112                         {
113                                 me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
114                                 return 1;
115                         }
116                         if (me.scrList.keyDown(me.scrList, key, ascii, shift))
117                         {
118                                 // keyDown has already changed the selected item
119                                 me.scrList.goScreenshot(me.scrList, 0);
120                                 return 1;
121                         }
122                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
123         }
124 }
125 void XonoticScreenshotViewerDialog_close(entity me)
126 {
127         // resume music
128         if(!cvar("menu_screenshotviewer_enablemusic"))
129         if(cvar("music_playlist_index") == 999)
130         {
131                 cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
132         }
133         else
134                 localcmd("\ncd resume\n");
135
136         me.scrList.stopSlideShow(me.scrList);
137         me.slideShowButton.forcePressed = 0;
138         SUPER(XonoticScreenshotViewerDialog).close(me);
139 }
140 void XonoticScreenshotViewerDialog_fill(entity me)
141 {
142         entity e;
143         me.TR(me);
144                 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
145                         e.showTitle = 0; // dialog title is enough
146                         me.screenshotImage = e;
147         me.gotoRC(me, me.rows - 1, 0);
148                 me.TDempty(me, 1/20 * me.columns);
149                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
150                         e.onClick = decreaseZoom_Click;
151                         e.onClickEntity = me;
152                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
153                         e.onClick = increaseZoom_Click;
154                         e.onClickEntity = me;
155                 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
156                         e.onClick = resetZoom_Click;
157                         e.onClickEntity = me;
158
159                 me.TDempty(me, 2/20 * me.columns);
160                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
161                         e.onClick = prevScreenshot_Click;
162                         e.onClickEntity = me;
163                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
164                         e.onClick = nextScreenshot_Click;
165                         e.onClickEntity = me;
166
167                 me.TDempty(me, 2/20 * me.columns);
168                 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
169                         e.onClick = toggleSlideShow_Click;
170                         e.onClickEntity = me;
171                         me.slideShowButton = e;
172 }
173 #endif