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