1-- _________ __ __ 2-- / _____// |_____________ _/ |______ ____ __ __ ______ 3-- \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 4-- / \| | | | \// __ \| | / __ \_/ /_/ | /\___ \ 5-- /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 6-- \/ \/ \//_____/ \/ 7-- ______________________ ______________________ 8-- T H E W A R B E G I N S 9-- Stratagus - A free fantasy real time strategy game engine 10-- 11-- ui.lua - Define the human user interface 12-- 13-- (c) Copyright 2001-2008 by Lutz Sammer and Jimmy Salmon 14-- 15-- This program is free software; you can redistribute it and/or modify 16-- it under the terms of the GNU General Public License as published by 17-- the Free Software Foundation; either version 2 of the License, or 18-- (at your option) any later version. 19-- 20-- This program is distributed in the hope that it will be useful, 21-- but WITHOUT ANY WARRANTY; without even the implied warranty of 22-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23-- GNU General Public License for more details. 24-- 25-- You should have received a copy of the GNU General Public License 26-- along with this program; if not, write to the Free Software 27-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28-- 29 30DefineCursor({ 31 Name = "cursor-point", 32 Race = "human", 33 File = "ui/human/cursors/human_gauntlet.png", 34 HotSpot = { 3, 2}, 35 Size = {28, 32}}) 36DefineCursor({ 37 Name = "cursor-green-hair", 38 Race = "human", 39 File = "ui/human/cursors/green_eagle.png", 40 HotSpot = {15, 15}, 41 Size = {32, 32}}) 42DefineCursor({ 43 Name = "cursor-yellow-hair", 44 Race = "human", 45 File = "ui/human/cursors/yellow_eagle.png", 46 HotSpot = {15, 15}, 47 Size = {32, 32}}) 48DefineCursor({ 49 Name = "cursor-red-hair", 50 Race = "human", 51 File = "ui/human/cursors/red_eagle.png", 52 HotSpot = {15, 15}, 53 Size = {32, 32}}) 54 55--;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 56-- * Race human. 57--;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 58 59wargus.playlist = { "music/Human Battle 1" .. wargus.music_extension, "music/Human Battle 2" .. wargus.music_extension, 60 "music/Human Battle 3" .. wargus.music_extension, "music/Human Battle 4" .. wargus.music_extension, "music/Human Battle 5" .. wargus.music_extension} 61 62if (wargus.bne == true) then 63 table.insert(wargus.playlist, "music/Human Battle 6" .. wargus.music_extension) 64end 65 66function HumanScreen(screen_width, screen_height) 67 local info_panel_x = 0 68 local info_panel_y = 160 69 70 local ui = { 71 "info-panel", { 72 "panels", {"panel-general-contents", "panel-attack-unit-contents", 73 "panel-all-unit-contents", "panel-building-contents"}, 74 "completed-bar", { 75 "color", {48, 100, 4} 76 } 77 } 78 } 79end 80 81UI.NormalFontColor = "white" 82UI.ReverseFontColor = "yellow" 83 84UI.Fillers:clear() 85 86function AddFiller(file, x, y) 87 if CanAccessFile(file) == true then 88 b = CFiller:new_local() 89 b.G = CGraphic:New(file) 90 b.X = x 91 b.Y = y 92 UI.Fillers:push_back(b) 93 end 94end 95 96function AddResizedFiller(file, x, y, width, height) 97 if CanAccessFile(file) == true then 98 b = CFiller:new_local() 99 b.G = CGraphic:New(file) 100 b.G:Load() 101 b.G:Resize(width, height) 102 b.X = x 103 b.Y = y 104 UI.Fillers:push_back(b) 105 end 106end 107 108AddResizedFiller("ui/human/filler-right.png", Video.Width - 16, 0, 16, Video.Height) 109AddResizedFiller("ui/human/resource.png", 176, 0, Video.Width - 192, 16) 110AddResizedFiller("ui/human/statusline.png", 176, Video.Height - 16, Video.Width - 192, 16) 111AddResizedFiller("ui/human/buttonpanel.png", 0, 336, 176, 144 + Video.Height - 480) 112 113AddFiller("ui/human/menubutton.png", 0, 0) 114AddFiller("ui/human/minimap.png", 0, 24) 115 116UI.InfoPanel.X = 0 117UI.InfoPanel.Y = 160 118UI.InfoPanel.G = CGraphic:New("ui/human/infopanel.png", 176, 176) 119 120b = CUIButton:new() 121b.X = 9 122b.Y = 160 + 9 123b.Style = FindButtonStyle("icon") 124UI.SingleSelectedButton = b 125 126UI.SelectedButtons:clear() 127 128function AddSelectedButton(x, y) 129 b = CUIButton:new_local() 130 b.X = x 131 b.Y = y 132 b.Style = FindButtonStyle("icon") 133 UI.SelectedButtons:push_back(b) 134end 135 136AddSelectedButton(9, 160 + 9) 137AddSelectedButton(65, 160 + 9) 138AddSelectedButton(121, 160 + 9) 139AddSelectedButton(9, 160 + 63) 140AddSelectedButton(65, 160 + 63) 141AddSelectedButton(121, 160 + 63) 142AddSelectedButton(9, 160 + 117) 143AddSelectedButton(65, 160 + 117) 144AddSelectedButton(121, 160 + 117) 145 146UI.MaxSelectedFont = Fonts["game"] 147UI.MaxSelectedTextX = 10 148UI.MaxSelectedTextY = 160 + 10 149 150b = CUIButton:new() 151b.X = 110 152b.Y = 160 + 11 + 70 153b.Style = FindButtonStyle("icon") 154UI.SingleTrainingButton = b 155 156UI.TrainingButtons:clear() 157 158function AddTrainingButton(x, y) 159 b = CUIButton:new_local() 160 b.X = x 161 b.Y = y 162 b.Style = FindButtonStyle("icon") 163 UI.TrainingButtons:push_back(b) 164end 165 166AddTrainingButton(9, 219) 167AddTrainingButton(65, 219) 168AddTrainingButton(121, 219) 169AddTrainingButton(9, 266) 170AddTrainingButton(65, 266) 171AddTrainingButton(121, 266) 172 173b = CUIButton:new() 174b.X = 110 175b.Y = 160 + 11 + 70 176b.Style = FindButtonStyle("icon") 177UI.UpgradingButton = b 178 179b = CUIButton:new() 180b.X = 110 181b.Y = 160 + 11 + 70 182b.Style = FindButtonStyle("icon") 183UI.ResearchingButton = b 184 185UI.TransportingButtons:clear() 186 187function AddTransportingButton(x, y) 188 b = CUIButton:new_local() 189 b.X = x 190 b.Y = y 191 b.Style = FindButtonStyle("icon") 192 UI.TransportingButtons:push_back(b) 193end 194 195AddTransportingButton(9, 387) 196AddTransportingButton(65, 387) 197AddTransportingButton(121, 387) 198AddTransportingButton(9, 434) 199AddTransportingButton(65, 434) 200AddTransportingButton(121, 434) 201 202UI.CompletedBarColorRGB = CColor(48, 100, 4) 203UI.CompletedBarShadow = false 204 205UI.ButtonPanel.Buttons:clear() 206 207function AddButtonPanelButton(x, y) 208 b = CUIButton:new_local() 209 b.X = x 210 b.Y = y 211 b.Style = FindButtonStyle("icon") 212 UI.ButtonPanel.Buttons:push_back(b) 213end 214 215AddButtonPanelButton(9, 340) 216AddButtonPanelButton(65, 340) 217AddButtonPanelButton(121, 340) 218AddButtonPanelButton(9, 387) 219AddButtonPanelButton(65, 387) 220AddButtonPanelButton(121, 387) 221AddButtonPanelButton(9, 434) 222AddButtonPanelButton(65, 434) 223AddButtonPanelButton(121, 434) 224 225UI.ButtonPanel.X = 0 226UI.ButtonPanel.Y = 336 227UI.ButtonPanel.AutoCastBorderColorRGB = CColor(0, 0, 252) 228 229UI.MapArea.X = 176 230UI.MapArea.Y = 16 231UI.MapArea.EndX = Video.Width - 16 - 1 232UI.MapArea.EndY = Video.Height - 16 - 1 233 234UI.Minimap.X = 24 235UI.Minimap.Y = 24 + 2 236UI.Minimap.W = 128 237UI.Minimap.H = 128 238 239UI.StatusLine.TextX = 2 + 176 240UI.StatusLine.TextY = Video.Height + 2 - 16 241UI.StatusLine.Width = Video.Width - 16 - 2 - 176 242UI.StatusLine.Font = Fonts["game"] 243 244-- gold 245UI.Resources[1].G = CGraphic:New("ui/gold,wood,oil,mana.png", 14, 14) 246UI.Resources[1].IconFrame = 0 247UI.Resources[1].IconX = 176 + 0 248UI.Resources[1].IconY = 0 249UI.Resources[1].TextX = 176 + 0 + 18 250UI.Resources[1].TextY = 1 251 252-- wood 253UI.Resources[2].G = CGraphic:New("ui/gold,wood,oil,mana.png", 14, 14) 254UI.Resources[2].IconFrame = 1 255UI.Resources[2].IconX = 176 + 75 256UI.Resources[2].IconY = 0 257UI.Resources[2].TextX = 176 + 75 + 18 258UI.Resources[2].TextY = 1 259 260-- oil 261UI.Resources[3].G = CGraphic:New("ui/gold,wood,oil,mana.png", 14, 14) 262UI.Resources[3].IconFrame = 2 263UI.Resources[3].IconX = 176 + 150 264UI.Resources[3].IconY = 0 265UI.Resources[3].TextX = 176 + 150 + 18 266UI.Resources[3].TextY = 1 267 268-- food 269if (CanAccessFile("ui/food.png")) then 270 UI.Resources[FoodCost].G = CGraphic:New("ui/food.png", 14, 14) 271end 272UI.Resources[FoodCost].IconFrame = 0 273UI.Resources[FoodCost].IconX = Video.Width - 16 - 154 274UI.Resources[FoodCost].IconY = 0 275UI.Resources[FoodCost].TextX = Video.Width - 16 - 154 + 18 276UI.Resources[FoodCost].TextY = 1 277 278-- score 279if (CanAccessFile("ui/score.png"))then 280 UI.Resources[ScoreCost].G = CGraphic:New("ui/score.png", 14, 14) 281end 282UI.Resources[ScoreCost].IconFrame = 0 283UI.Resources[ScoreCost].IconX = Video.Width - 16 - 84 284UI.Resources[ScoreCost].IconY = 0 285UI.Resources[ScoreCost].TextX = Video.Width - 16 - 84 + 18 286UI.Resources[ScoreCost].TextY = 1 287 288-- mana 289if (CanAccessFile("ui/gold,wood,oil,mana.png"))then 290 UI.Resources[ManaResCost].G = CGraphic:New("ui/gold,wood,oil,mana.png", 14, 14) 291end 292UI.Resources[ManaResCost].IconFrame = 3 293UI.Resources[ManaResCost].IconX = -100 294UI.Resources[ManaResCost].IconY = -100 295UI.Resources[ManaResCost].TextX = -100 296UI.Resources[ManaResCost].TextY = -100 297 298if (CanAccessFile("ui/workers.png"))then 299 UI.Resources[FreeWorkersCount].G = CGraphic:New("ui/workers.png", 14, 14) 300end 301UI.Resources[FreeWorkersCount].IconFrame = 0 302UI.Resources[FreeWorkersCount].IconX = Video.Width - 16 - 24 303UI.Resources[FreeWorkersCount].IconY = 0 304UI.Resources[FreeWorkersCount].TextX = Video.Width - 16 - 24 + 18 305UI.Resources[FreeWorkersCount].TextY = 1 306 307UI.MenuButton.X = 24 308UI.MenuButton.Y = 2 309UI.MenuButton.Text = _("Menu (~<F10~>)") 310UI.MenuButton.Style = FindButtonStyle("main") 311UI.MenuButton:SetCallback( 312 function() 313 if (Editor.Running == EditorNotRunning) then 314 RunGameMenu() 315 else 316 RunInEditorMenu() 317 end 318 end) 319 320UI.NetworkMenuButton.X = 6 321UI.NetworkMenuButton.Y = 2 322UI.NetworkMenuButton.Text = _("Menu") 323UI.NetworkMenuButton.Style = FindButtonStyle("network") 324UI.NetworkMenuButton:SetCallback(function() RunGameMenu() end) 325 326UI.NetworkDiplomacyButton.X = 90 327UI.NetworkDiplomacyButton.Y = 2 328UI.NetworkDiplomacyButton.Text = _("Diplomacy") 329UI.NetworkDiplomacyButton.Style = FindButtonStyle("network") 330UI.NetworkDiplomacyButton:SetCallback(function() RunDiplomacyMenu() end) 331