~ubuntu-branches/ubuntu/natty/spring/natty

« back to all changes in this revision

Viewing changes to rts/Game/UI/GuiHandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Ritchie
  • Date: 2010-09-23 18:56:03 UTC
  • mfrom: (3.1.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100923185603-st97s5chplo42y7w
Tags: 0.82.5.1+dfsg1-1ubuntu1
* Latest upstream version for online play
* debian/control: Replace (rather than conflict) spring-engine
  - spring-engine will be a dummy package (LP: #612905)
  - also set maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
 
2
 
1
3
#include "StdAfx.h"
2
 
// GuiHandler.cpp: implementation of the CGuiHandler class.
3
 
//
4
 
//////////////////////////////////////////////////////////////////////
5
4
 
6
5
#include <map>
7
6
#include <set>
32
31
#include "Map/ReadMap.h"
33
32
#include "Rendering/glFont.h"
34
33
#include "Rendering/IconHandler.h"
 
34
#include "Rendering/UnitDrawer.h"
35
35
#include "Rendering/GL/glExtra.h"
36
36
#include "Rendering/Textures/Bitmap.h"
37
37
#include "Rendering/Textures/NamedTextures.h"
38
 
#include "Rendering/UnitModels/3DOParser.h"
39
 
#include "Rendering/UnitModels/UnitDrawer.h"
40
38
#include "Sim/Features/Feature.h"
41
39
#include "Sim/Misc/LosHandler.h"
42
40
#include "Sim/Units/CommandAI/CommandAI.h"
47
45
#include "Sim/Units/UnitLoader.h"
48
46
#include "Sim/Weapons/WeaponDefHandler.h"
49
47
#include "Sim/Weapons/Weapon.h"
50
 
#include "Sound/AudioChannel.h"
51
 
#include "Sound/Sound.h"
 
48
#include "Sound/IEffectChannel.h"
 
49
#include "Sound/ISound.h"
52
50
#include "EventHandler.h"
53
51
#include "FileSystem/SimpleParser.h"
54
52
#include "LogOutput.h"
79
77
        activePage(0),
80
78
        defaultCmdMemory(-1),
81
79
        explicitCommand(-1),
 
80
        curIconCommand(-1),
82
81
        actionOffset(0),
83
82
        drawSelectionInfo(true),
 
83
        hasLuaUILayoutCommands(false),
84
84
        gatherMode(false)
85
85
{
86
86
        icons = new IconInfo[16];
87
87
        iconsSize = 16;
88
88
        iconsCount = 0;
89
89
 
 
90
        LoadDefaults();
90
91
        LoadConfig("ctrlpanel.txt");
91
92
 
92
93
        miniMapMarker = !!configHandler->Get("MiniMapMarker", 1);
177
178
 
178
179
bool CGuiHandler::LoadConfig(const std::string& filename)
179
180
{
180
 
        LoadDefaults();
181
 
 
182
181
        CFileHandler ifs(filename);
183
182
        CSimpleParser parser(ifs);
184
183
 
924
923
 
925
924
void CGuiHandler::Update()
926
925
{
 
926
        RunLayoutCommands();
 
927
 
927
928
        GML_RECMUTEX_LOCK(gui); // Update - updates inCommand
928
929
 
929
930
        SetCursorIcon();
1039
1040
{
1040
1041
        GML_RECMUTEX_LOCK(gui); // MousePress - updates inCommand
1041
1042
 
1042
 
        if (button == SDL_BUTTON_MIDDLE) {
 
1043
        if (button != SDL_BUTTON_LEFT && button != SDL_BUTTON_RIGHT && button != -SDL_BUTTON_RIGHT && button != -SDL_BUTTON_LEFT)
1043
1044
                return false;
1044
 
        }
1045
1045
 
1046
1046
        if (button < 0) {
1047
1047
                // proxied click from the minimap
1050
1050
        }
1051
1051
        else if (AboveGui(x,y)) {
1052
1052
                activeMousePress = true;
 
1053
                if ((curIconCommand < 0) && !game->hideInterface) {
 
1054
                        const int iconPos = IconAtPos(x, y);
 
1055
                        if (iconPos >= 0) {
 
1056
                                curIconCommand = icons[iconPos].commandsID;
 
1057
                        }
 
1058
                }
 
1059
                if (button == SDL_BUTTON_RIGHT)
 
1060
                        inCommand = defaultCmdMemory = -1;
1053
1061
                return true;
1054
1062
        }
1055
1063
        else if (minimap && minimap->IsAbove(x, y)) {
1080
1088
 
1081
1089
void CGuiHandler::MouseRelease(int x, int y, int button, float3& camerapos, float3& mousedir)
1082
1090
{
 
1091
        GML_RECMUTEX_LOCK(gui); // MouseRelease
 
1092
 
 
1093
        if (button != SDL_BUTTON_LEFT && button != SDL_BUTTON_RIGHT && button != -SDL_BUTTON_RIGHT && button != -SDL_BUTTON_LEFT)
 
1094
                return;
 
1095
 
 
1096
        int lastIconCmd = curIconCommand;
 
1097
        curIconCommand = -1;
 
1098
 
1083
1099
        int iconCmd = -1;
1084
 
 
1085
 
        if (button != SDL_BUTTON_MIDDLE) {
1086
 
                explicitCommand = inCommand;
1087
 
        }
 
1100
        explicitCommand = inCommand;
1088
1101
 
1089
1102
        if (activeMousePress) {
1090
1103
                activeMousePress = false;
1102
1115
                button = -button; // proxied click from the minimap
1103
1116
        } else {
1104
1117
                // setup iconCmd
1105
 
                if ((iconCmd < 0) && !game->hideInterface) {
 
1118
                if (!game->hideInterface) {
1106
1119
                        const int iconPos = IconAtPos(x, y);
1107
1120
                        if (iconPos >= 0) {
1108
1121
                                iconCmd = icons[iconPos].commandsID;
 
1122
                                if(iconCmd != lastIconCmd)
 
1123
                                        iconCmd = -1; // mouse was pressed on one button and released on another one --> ignore the command
1109
1124
                        }
1110
1125
                }
1111
1126
        }
1478
1493
        float maxV = 100.0f;
1479
1494
        if (cd.params.size() >= 1) { minV = atof(cd.params[0].c_str()); }
1480
1495
        if (cd.params.size() >= 2) { maxV = atof(cd.params[1].c_str()); }
1481
 
        const int minX = (gu->viewSizeX * 1) / 4;
1482
 
        const int maxX = (gu->viewSizeX * 3) / 4;
 
1496
        const int minX = (globalRendering->viewSizeX * 1) / 4;
 
1497
        const int maxX = (globalRendering->viewSizeX * 3) / 4;
1483
1498
        const int effX = std::max(std::min(mouse->lastx, maxX), minX);
1484
1499
        const float factor = float(effX - minX) / float(maxX - minX);
1485
1500
 
1512
1527
        else {
1513
1528
                const float3 camPos = camerapos;
1514
1529
                const float3 camDir = mousedir;
1515
 
                const float viewRange = gu->viewRange*1.4f;
 
1530
                const float viewRange = globalRendering->viewRange*1.4f;
1516
1531
                const float dist = helper->GuiTraceRay(camPos, camDir, viewRange, unit, true);
1517
1532
                const float dist2 = helper->GuiTraceRayFeature(camPos, camDir, viewRange, feature);
1518
1533
                const float3 hit = camPos + camDir*dist;
1612
1627
                return true;
1613
1628
        }
1614
1629
        else if (action.command == "luaui") {
1615
 
                RunLayoutCommand(action.extra);
 
1630
                PushLayoutCommand(action.extra);
1616
1631
                return true;
1617
1632
        }
1618
1633
        else if (action.command == "invqueuekey") {
2101
2116
                        return c;}
2102
2117
 
2103
2118
                case CMDTYPE_ICON_MAP:{
2104
 
                        float dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
2119
                        float dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
2105
2120
                        if(dist<0){
2106
2121
                                return defaultRet;
2107
2122
                        }
2115
2130
                        return c;}
2116
2131
 
2117
2132
                case CMDTYPE_ICON_BUILDING:{
2118
 
                        float dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
2133
                        float dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
2119
2134
                        if(dist<0){
2120
2135
                                return defaultRet;
2121
2136
                        }
2129
2144
                        std::vector<BuildInfo> buildPos;
2130
2145
                        BuildInfo bi(unitdef, pos, buildFacing);
2131
2146
                        if(GetQueueKeystate() && button==SDL_BUTTON_LEFT){
2132
 
                                float dist=ground->LineGroundCol(mouse->buttons[SDL_BUTTON_LEFT].camPos,mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*gu->viewRange*1.4f);
 
2147
                                float dist=ground->LineGroundCol(mouse->buttons[SDL_BUTTON_LEFT].camPos,mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*globalRendering->viewRange*1.4f);
2133
2148
                                float3 pos2=mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*dist;
2134
2149
                                buildPos=GetBuildPos(BuildInfo(unitdef,pos2,buildFacing),bi,camerapos,mousedir);
2135
2150
                        } else
2167
2182
                        Command c;
2168
2183
 
2169
2184
                        c.id=commands[tempInCommand].id;
2170
 
                        helper->GuiTraceRay(camerapos,mousedir,gu->viewRange*1.4f,unit,true);
 
2185
                        helper->GuiTraceRay(camerapos,mousedir,globalRendering->viewRange*1.4f,unit,true);
2171
2186
                        if (!unit) {
2172
2187
                                return defaultRet;
2173
2188
                        }
2181
2196
                        c.id=commands[tempInCommand].id;
2182
2197
 
2183
2198
                        const CUnit* unit = NULL;
2184
 
                        float dist2 = helper->GuiTraceRay(camerapos,mousedir,gu->viewRange*1.4f,unit,true);
2185
 
                        if(dist2 > (gu->viewRange * 1.4f - 300)) {
 
2199
                        float dist2 = helper->GuiTraceRay(camerapos,mousedir,globalRendering->viewRange*1.4f,unit,true);
 
2200
                        if(dist2 > (globalRendering->viewRange * 1.4f - 300)) {
2186
2201
                                return defaultRet;
2187
2202
                        }
2188
2203
 
2204
2219
 
2205
2220
                        float dist = ground->LineGroundCol(
2206
2221
                                mouse->buttons[button].camPos,
2207
 
                                mouse->buttons[button].camPos + mouse->buttons[button].dir * gu->viewRange * 1.4f);
 
2222
                                mouse->buttons[button].camPos + mouse->buttons[button].dir * globalRendering->viewRange * 1.4f);
2208
2223
                        if(dist<0){
2209
2224
                                return defaultRet;
2210
2225
                        }
2215
2230
                        c.params.push_back(pos.z);
2216
2231
 
2217
2232
                        if(mouse->buttons[button].movement>30){         //only create the front if the mouse has moved enough
2218
 
                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
2233
                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
2219
2234
                                if(dist<0){
2220
2235
                                        return defaultRet;
2221
2236
                                }
2258
2273
 
2259
2274
                                const CUnit* unit = NULL;
2260
2275
                                const CFeature* feature = NULL;
2261
 
                                float dist2 = helper->GuiTraceRay(camerapos,mousedir,gu->viewRange*1.4f,unit,true);
2262
 
                                float dist3 = helper->GuiTraceRayFeature(camerapos,mousedir,gu->viewRange*1.4f,feature);
 
2276
                                float dist2 = helper->GuiTraceRay(camerapos,mousedir,globalRendering->viewRange*1.4f,unit,true);
 
2277
                                float dist3 = helper->GuiTraceRayFeature(camerapos,mousedir,globalRendering->viewRange*1.4f,feature);
2263
2278
 
2264
 
                                if(dist2 > (gu->viewRange * 1.4f - 300) && (commands[tempInCommand].type!=CMDTYPE_ICON_UNIT_FEATURE_OR_AREA || dist3>gu->viewRange*1.4f-300)) {
 
2279
                                if(dist2 > (globalRendering->viewRange * 1.4f - 300) && (commands[tempInCommand].type!=CMDTYPE_ICON_UNIT_FEATURE_OR_AREA || dist3>globalRendering->viewRange*1.4f-300)) {
2265
2280
                                        return defaultRet;
2266
2281
                                }
2267
2282
 
2279
2294
                                        c.params.push_back(0);//zero radius
2280
2295
                                }
2281
2296
                        } else {        //created area
2282
 
                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*gu->viewRange*1.4f);
 
2297
                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*globalRendering->viewRange*1.4f);
2283
2298
                                if(dist<0){
2284
2299
                                        return defaultRet;
2285
2300
                                }
2287
2302
                                c.params.push_back(pos.x);
2288
2303
                                c.params.push_back(pos.y);
2289
2304
                                c.params.push_back(pos.z);
2290
 
                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
2305
                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
2291
2306
                                if(dist<0){
2292
2307
                                        return defaultRet;
2293
2308
                                }
2304
2319
                        if (mouse->buttons[button].movement < 16) {
2305
2320
                                const CUnit* unit = NULL;
2306
2321
 
2307
 
                                float dist2 = helper->GuiTraceRay(camerapos, mousedir, gu->viewRange*1.4f, unit, true);
 
2322
                                float dist2 = helper->GuiTraceRay(camerapos, mousedir, globalRendering->viewRange*1.4f, unit, true);
2308
2323
 
2309
 
                                if (dist2 > (gu->viewRange * 1.4f - 300)) {
 
2324
                                if (dist2 > (globalRendering->viewRange * 1.4f - 300)) {
2310
2325
                                        return defaultRet;
2311
2326
                                }
2312
2327
 
2327
2342
                                // created rectangle
2328
2343
                                float dist = ground->LineGroundCol(
2329
2344
                                        mouse->buttons[button].camPos,
2330
 
                                        mouse->buttons[button].camPos + mouse->buttons[button].dir * gu->viewRange*1.4f);
 
2345
                                        mouse->buttons[button].camPos + mouse->buttons[button].dir * globalRendering->viewRange*1.4f);
2331
2346
                                if(dist<0){
2332
2347
                                        return defaultRet;
2333
2348
                                }
2334
2349
                                float3 startPos = mouse->buttons[button].camPos + mouse->buttons[button].dir * dist;
2335
 
                                dist = ground->LineGroundCol(camerapos, camerapos + mousedir*gu->viewRange * 1.4f);
 
2350
                                dist = ground->LineGroundCol(camerapos, camerapos + mousedir*globalRendering->viewRange * 1.4f);
2336
2351
                                if(dist<0){
2337
2352
                                        return defaultRet;
2338
2353
                                }
2401
2416
 
2402
2417
                GML_RECMUTEX_LOCK(quad); // GetBuildCommand - accesses activeunits - called from DrawMapStuff -> GetBuildPos
2403
2418
 
2404
 
                helper->GuiTraceRay(camerapos,mousedir,gu->viewRange*1.4f,unit,true);
 
2419
                helper->GuiTraceRay(camerapos,mousedir,globalRendering->viewRange*1.4f,unit,true);
2405
2420
                if (unit) {
2406
2421
                        other.def = unit->unitDef;
2407
2422
                        other.pos = unit->pos;
2563
2578
 
2564
2579
bool CGuiHandler::DrawUnitBuildIcon(const IconInfo& icon, int unitDefID)
2565
2580
{
2566
 
        // UnitDefHandler's array size is (numUnitDefs + 1)
2567
 
        if ((unitDefID <= 0) || (unitDefID > unitDefHandler->numUnitDefs)) {
2568
 
                return false;
2569
 
        }
2570
 
 
2571
2581
        const UnitDef* ud = unitDefHandler->GetUnitDefByID(unitDefID);
2572
 
        if (ud != NULL) {
 
2582
        if (ud) {
2573
2583
                const Box& b = icon.visual;
2574
2584
                glEnable(GL_TEXTURE_2D);
2575
2585
                glColor4f(1.0f, 1.0f, 1.0f, textureAlpha);
2622
2632
        if (endPtr == startPtr) {
2623
2633
                return false; // bad unitID spec
2624
2634
        }
2625
 
        // UnitDefHandler's array size is (numUnitDefs + 1)
2626
 
        if ((unitDefID <= 0) || (unitDefID > unitDefHandler->numUnitDefs)) {
2627
 
                return false;
2628
 
        }
 
2635
 
2629
2636
        const UnitDef* ud = unitDefHandler->GetUnitDefByID(unitDefID);
2630
2637
        if (ud == NULL) {
2631
2638
                return false;
2645
2652
        if (endPtr == startPtr) {
2646
2653
                return false; // bad unitID spec
2647
2654
        }
2648
 
        // UnitDefHandler's array size is (numUnitDefs + 1)
2649
 
        if ((unitDefID <= 0) || (unitDefID > unitDefHandler->numUnitDefs)) {
2650
 
                return false;
2651
 
        }
 
2655
 
2652
2656
        const UnitDef* ud = unitDefHandler->GetUnitDefByID(unitDefID);
2653
2657
        if (ud == NULL) {
2654
2658
                return false;
2803
2807
 
2804
2808
        const float yShrink = offsetForLEDs ? (0.125f * yIconSize) : 0.0f;
2805
2809
 
2806
 
        const float tWidth  = font->GetSize() * font->GetTextWidth(text) * gu->pixelX;  //FIXME
2807
 
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * gu->pixelY; //FIXME merge in 1 function?
 
2810
        const float tWidth  = font->GetSize() * font->GetTextWidth(text) * globalRendering->pixelX;  //FIXME
 
2811
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * globalRendering->pixelY; //FIXME merge in 1 function?
2808
2812
        const float textBorder2 = (2.0f * textBorder);
2809
2813
        float xScale = (xIconSize - textBorder2) / tWidth;
2810
2814
        float yScale = (yIconSize - textBorder2 - yShrink) / tHeight;
2824
2828
                return;
2825
2829
        }
2826
2830
        const Box& b = icon.visual;
2827
 
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * gu->pixelY;
 
2831
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * globalRendering->pixelY;
2828
2832
        const float fontScale = (yIconSize * 0.2f) / tHeight;
2829
2833
        const float xPos = b.x1 + textBorder + 0.002f;
2830
2834
        const float yPos = b.y1 - textBorder - 0.006f;
2839
2843
                return;
2840
2844
        }
2841
2845
        const Box& b = icon.visual;
2842
 
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * gu->pixelY;
 
2846
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * globalRendering->pixelY;
2843
2847
        const float fontScale = (yIconSize * 0.2f) / tHeight;
2844
2848
        const float xPos = b.x1 + textBorder + 0.002f;
2845
2849
        const float yPos = b.y2 + textBorder + 0.002f;
2854
2858
                return;
2855
2859
        }
2856
2860
        const Box& b = icon.visual;
2857
 
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * gu->pixelY;
 
2861
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * globalRendering->pixelY;
2858
2862
        const float fontScale = (yIconSize * 0.2f) / tHeight;
2859
2863
        const float xPos = b.x2 - textBorder - 0.002f;
2860
2864
        const float yPos = b.y1 - textBorder - 0.006f;
2869
2873
                return;
2870
2874
        }
2871
2875
        const Box& b = icon.visual;
2872
 
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * gu->pixelY;
 
2876
        const float tHeight = font->GetSize() * font->GetTextHeight(text) * globalRendering->pixelY;
2873
2877
        const float fontScale = (yIconSize * 0.2f) / tHeight;
2874
2878
        const float xPos = b.x2 - textBorder - 0.002f;
2875
2879
        const float yPos = b.y2 + textBorder + 0.002f;
3071
3075
                const float yp = buttonBox.y2 + (yIconSize * 0.125f);
3072
3076
 
3073
3077
                if (!outlineFonts) {
3074
 
                        const float textHeight = fontScale * font->GetTextHeight(menuName) * gu->pixelY;
 
3078
                        const float textHeight = fontScale * font->GetTextHeight(menuName) * globalRendering->pixelY;
3075
3079
                        glDisable(GL_TEXTURE_2D);
3076
3080
                        glColor4f(0.2f, 0.2f, 0.2f, guiAlpha);
3077
3081
                        glRectf(buttonBox.x1,
3107
3111
 
3108
3112
                if (!outlineFonts) {
3109
3113
                        float descender;
3110
 
                        const float textWidth  = fontSize * smallFont->GetTextWidth(buf.str()) * gu->pixelX;
3111
 
                        float textHeight = fontSize * smallFont->GetTextHeight(buf.str(), &descender) * gu->pixelY;
3112
 
                        const float textDescender = fontSize * descender * gu->pixelY; //! descender is always negative
 
3114
                        const float textWidth  = fontSize * smallFont->GetTextWidth(buf.str()) * globalRendering->pixelX;
 
3115
                        float textHeight = fontSize * smallFont->GetTextHeight(buf.str(), &descender) * globalRendering->pixelY;
 
3116
                        const float textDescender = fontSize * descender * globalRendering->pixelY; //! descender is always negative
3113
3117
                        textHeight -= textDescender;
3114
3118
 
3115
3119
                        glDisable(GL_TEXTURE_2D);
3137
3141
                        const float value = GetNumberInput(cd);
3138
3142
                        glDisable(GL_TEXTURE_2D);
3139
3143
                        glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
3140
 
                        const float mouseX = (float)mouse->lastx / (float)gu->viewSizeX;
 
3144
                        const float mouseX = (float)mouse->lastx / (float)globalRendering->viewSizeX;
3141
3145
                        const float slideX = std::min(std::max(mouseX, 0.25f), 0.75f);
3142
 
                        //const float mouseY = 1.0f - (float)(mouse->lasty - 16) / (float)gu->viewSizeY;
 
3146
                        //const float mouseY = 1.0f - (float)(mouse->lasty - 16) / (float)globalRendering->viewSizeY;
3143
3147
                        glColor4f(1.0f, 1.0f, 0.0f, 0.8f);
3144
3148
                        glRectf(0.235f, 0.45f, 0.25f, 0.55f);
3145
3149
                        glRectf(0.75f, 0.45f, 0.765f, 0.55f);
3215
3219
        const float ys = yIconSize * 0.125f;
3216
3220
        const float x1 = icon.visual.x1;
3217
3221
        const float y2 = icon.visual.y2;
3218
 
        const float yp = 1.0f / float(gu->viewSizeY);
 
3222
        const float yp = 1.0f / float(globalRendering->viewSizeY);
3219
3223
 
3220
3224
        for (int x = 0; x < pCount; x++) {
3221
3225
                if (x != option) {
3333
3337
        }
3334
3338
 
3335
3339
        // copied from Weapon.cpp
3336
 
        const float3 interPos = unit->pos + (unit->speed * gu->timeOffset);
 
3340
        const float3 interPos = unit->pos + (unit->speed * globalRendering->timeOffset);
3337
3341
        float3 pos = interPos +
3338
3342
                     (unit->frontdir * w->relWeaponPos.z) +
3339
3343
                     (unit->updir    * w->relWeaponPos.y) +
3393
3397
                        }
3394
3398
                }
3395
3399
 
3396
 
                if ((cmdIndex >= 0) && ((size_t)cmdIndex < commands.size())) {
 
3400
                if (mouse->buttons[button].pressed && (cmdIndex >= 0) && ((size_t)cmdIndex < commands.size())) {
3397
3401
                        const CommandDescription& cmdDesc = commands[cmdIndex];
3398
3402
                        switch (cmdDesc.type) {
3399
3403
                                case CMDTYPE_ICON_FRONT: {
3418
3422
                                                maxRadius = atof(cmdDesc.params[0].c_str());
3419
3423
                                        }
3420
3424
                                        if (mouse->buttons[button].movement > 4) {
3421
 
                                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*gu->viewRange*1.4f);
 
3425
                                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*globalRendering->viewRange*1.4f);
3422
3426
                                                if(dist<0){
3423
3427
                                                        break;
3424
3428
                                                }
3425
3429
                                                float3 pos=mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
3426
 
                                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
3430
                                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
3427
3431
                                                if (dist < 0) {
3428
3432
                                                        break;
3429
3433
                                                }
3467
3471
                                }
3468
3472
                                case CMDTYPE_ICON_UNIT_OR_RECTANGLE:{
3469
3473
                                        if (mouse->buttons[button].movement >= 16) {
3470
 
                                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*gu->viewRange*1.4f);
 
3474
                                                float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*globalRendering->viewRange*1.4f);
3471
3475
                                                if (dist < 0) {
3472
3476
                                                        break;
3473
3477
                                                }
3474
3478
                                                const float3 pos1 = mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
3475
 
                                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
3479
                                                dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
3476
3480
                                                if (dist < 0) {
3477
3481
                                                        break;
3478
3482
                                                }
3514
3518
                        unit = minimap->GetSelectUnit(camerapos);
3515
3519
                } else {
3516
3520
                        // ignoring the returned distance
3517
 
                        helper->GuiTraceRay(camerapos,mousedir,gu->viewRange*1.4f,unit,false);
 
3521
                        helper->GuiTraceRay(camerapos,mousedir,globalRendering->viewRange*1.4f,unit,false);
3518
3522
                }
3519
3523
                if (unit && ((unit->losStatus[gu->myAllyTeam] & LOS_INLOS) || gu->spectatingFullView)) {
3520
3524
                        pointedAt = unit;
3534
3538
                        if (unit->decloakDistance > 0.0f) {
3535
3539
                                glColor4fv(cmdColors.rangeDecloak);
3536
3540
#ifndef USE_GML
3537
 
                                if (unit->unitDef->decloakSpherical && gu->drawdebug) {
 
3541
                                if (unit->unitDef->decloakSpherical && globalRendering->drawdebug) {
3538
3542
                                        glPushMatrix();
3539
3543
                                        glTranslatef(unit->midPos.x, unit->midPos.y, unit->midPos.z);
3540
3544
                                        glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
3625
3629
                        }
3626
3630
                }
3627
3631
 
3628
 
                float dist = ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
3632
                float dist = ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
3629
3633
                if (dist > 0) {
3630
3634
                        const UnitDef* unitdef = unitDefHandler->GetUnitDefByID(-commands[inCommand].id);
3631
3635
                        if (unitdef) {
3634
3638
                                std::vector<BuildInfo> buildPos;
3635
3639
                                const CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT];
3636
3640
                                if (GetQueueKeystate() && bp.pressed) {
3637
 
                                        const float dist = ground->LineGroundCol(bp.camPos, bp.camPos + bp.dir * gu->viewRange * 1.4f);
 
3641
                                        const float dist = ground->LineGroundCol(bp.camPos, bp.camPos + bp.dir * globalRendering->viewRange * 1.4f);
3638
3642
                                        const float3 pos2 = bp.camPos + bp.dir * dist;
3639
3643
                                        buildPos = GetBuildPos(BuildInfo(unitdef, pos2, buildFacing),
3640
3644
                                                               BuildInfo(unitdef, pos, buildFacing), camerapos, mousedir);
3707
3711
                                                        }
3708
3712
                                                }
3709
3713
                                        }
3710
 
                                        if (uh->ShowUnitBuildSquare(*bpi, cv)) {
 
3714
                                        if (unitDrawer->ShowUnitBuildSquare(*bpi, cv)) {
3711
3715
                                                glColor4f(0.7f,1,1,0.4f);
3712
3716
                                        } else {
3713
3717
                                                glColor4f(1,0.5f,0.5f,0.4f);
3785
3789
        const float groundLevel = ground->GetHeight(camerapos.x, camerapos.z);
3786
3790
 
3787
3791
        static float spinTime = 0.0f;
3788
 
        spinTime = fmod(spinTime + gu->lastFrameTime, 60.0f);
 
3792
        spinTime = fmod(spinTime + globalRendering->lastFrameTime, 60.0f);
3789
3793
 
3790
3794
        glPushMatrix();
3791
3795
        glTranslatef(camerapos.x, groundLevel, camerapos.z);
3867
3871
                        CMouseCursor* mc = mcit->second;
3868
3872
                        if (mc != NULL) {
3869
3873
                                glDisable(GL_DEPTH_TEST);
3870
 
                                mc->Draw((int)winPos.x, gu->viewSizeY - (int)winPos.y, 1.0f);
 
3874
                                mc->Draw((int)winPos.x, globalRendering->viewSizeY - (int)winPos.y, 1.0f);
3871
3875
                                glEnable(GL_DEPTH_TEST);
3872
3876
                        }
3873
3877
                }
3909
3913
        if(bp.movement<5){
3910
3914
                return;
3911
3915
        }
3912
 
        float dist=ground->LineGroundCol(bp.camPos,bp.camPos+bp.dir*gu->viewRange*1.4f);
 
3916
        float dist=ground->LineGroundCol(bp.camPos,bp.camPos+bp.dir*globalRendering->viewRange*1.4f);
3913
3917
        if(dist<0){
3914
3918
                return;
3915
3919
        }
3916
3920
        float3 pos1=bp.camPos+bp.dir*dist;
3917
 
        dist=ground->LineGroundCol(camerapos,camerapos+mousedir*gu->viewRange*1.4f);
 
3921
        dist=ground->LineGroundCol(camerapos,camerapos+mousedir*globalRendering->viewRange*1.4f);
3918
3922
        if(dist<0){
3919
3923
                return;
3920
3924
        }
4264
4268
 
4265
4269
/******************************************************************************/
4266
4270
/******************************************************************************/
 
4271
 
 
4272
 
 
4273
void CGuiHandler::PushLayoutCommand(const std::string& cmd, bool luacmd) {
 
4274
        GML_RECMUTEX_LOCK(laycmd); // PushLayoutCommand
 
4275
 
 
4276
        layoutCommands.push_back(cmd);
 
4277
        if(luacmd)
 
4278
                hasLuaUILayoutCommands = true;
 
4279
}
 
4280
 
 
4281
void CGuiHandler::RunLayoutCommands() {
 
4282
        bool luacmd = false;
 
4283
        std::vector<std::string> layoutCmds;
 
4284
 
 
4285
        if (!layoutCommands.empty()) {
 
4286
                GML_RECMUTEX_LOCK(laycmd); // RunLayoutCommands
 
4287
 
 
4288
                layoutCmds.swap(layoutCommands);
 
4289
                luacmd = hasLuaUILayoutCommands;
 
4290
                hasLuaUILayoutCommands = false;
 
4291
        }
 
4292
 
 
4293
        if(luacmd) {
 
4294
                GML_RECMUTEX_LOCK(sim); // RunLayoutCommands
 
4295
 
 
4296
                for (std::vector<std::string>::const_iterator cit = layoutCmds.begin(); cit != layoutCmds.end(); ++cit) {
 
4297
                        RunLayoutCommand(*cit);
 
4298
                }
 
4299
        } else {
 
4300
                for (std::vector<std::string>::const_iterator cit = layoutCmds.begin(); cit != layoutCmds.end(); ++cit) {
 
4301
                        RunLayoutCommand(*cit);
 
4302
                }
 
4303
        }
 
4304
}