Update the lua screens to use the new key display string API function.

develop
Alexander Gavrilov 2012-10-02 15:25:59 +04:00
parent 7440e80e6c
commit 9d5adf1b2f
7 changed files with 58 additions and 37 deletions

@ -93,6 +93,14 @@ function Painter.new(rect, pen)
return Painter{ rect = rect, pen = pen } return Painter{ rect = rect, pen = pen }
end end
function Painter.new_xy(x1,y1,x2,y2,pen)
return Painter{ rect = mkdims_xy(x1,y1,x2,y2), pen = pen }
end
function Painter.new_wh(x,y,w,h,pen)
return Painter{ rect = mkdims_wh(x,y,w,h), pen = pen }
end
function Painter:isValidPos() function Painter:isValidPos()
return self.x >= self.clip_x1 and self.x <= self.clip_x2 return self.x >= self.clip_x1 and self.x <= self.clip_x2
and self.y >= self.clip_y1 and self.y <= self.clip_y2 and self.y >= self.clip_y1 and self.y <= self.clip_y2
@ -210,6 +218,16 @@ function Painter:string(text,pen,...)
return self:advance(#text, nil) return self:advance(#text, nil)
end end
function Painter:key(code,pen,bg,...)
if type(code) == 'string' then
code = df.interface_key[code]
end
return self:string(
dscreen.getKeyDisplay(code),
pen or COLOR_LIGHTGREEN, bg or self.cur_pen.bg, ...
)
end
------------------------ ------------------------
-- Base screen object -- -- Base screen object --
------------------------ ------------------------

@ -51,10 +51,9 @@ function MessageBox:onRenderBody(dc)
end end
if self.on_accept then if self.on_accept then
local x,y = self.frame_rect.x1+1, self.frame_rect.y2+1 local fr = self.frame_rect
dscreen.paintString({fg=COLOR_LIGHTGREEN},x,y,'ESC') local dc2 = gui.Painter.new_xy(fr.x1+1,fr.y2+1,fr.x2-8,fr.y2+1)
dscreen.paintString({fg=COLOR_GREY},x+3,y,'/') dc2:key('LEAVESCREEN'):string('/'):key('MENU_CONFIRM')
dscreen.paintString({fg=COLOR_LIGHTGREEN},x+4,y,'y')
end end
end end

@ -17,8 +17,8 @@ local brushes = {
} }
local paints = { local paints = {
{ tag = 'water', caption = 'Water', liquid = true, flow = true, key = 'w' }, { tag = 'water', caption = 'Water', liquid = true, flow = true, key = 'D_LOOK_ARENA_WATER' },
{ tag = 'magma', caption = 'Magma', liquid = true, flow = true, key = 'l' }, { tag = 'magma', caption = 'Magma', liquid = true, flow = true, key = 'D_LOOK_ARENA_MAGMA' },
{ tag = 'obsidian', caption = 'Obsidian Wall' }, { tag = 'obsidian', caption = 'Obsidian Wall' },
{ tag = 'obsidian_floor', caption = 'Obsidian Floor' }, { tag = 'obsidian_floor', caption = 'Obsidian Floor' },
{ tag = 'riversource', caption = 'River Source' }, { tag = 'riversource', caption = 'River Source' },
@ -64,7 +64,7 @@ function Toggle:render(dc)
if item then if item then
dc:string(item.caption) dc:string(item.caption)
if item.key then if item.key then
dc:string(" ("):string(item.key, COLOR_LIGHTGREEN):string(")") dc:string(" ("):key(item.key):string(")")
end end
else else
dc:string('NONE', COLOR_RED) dc:string('NONE', COLOR_RED)
@ -160,9 +160,9 @@ function LiquidsUI:onRenderBody(dc)
dc:newline():pen(COLOR_GREY) dc:newline():pen(COLOR_GREY)
dc:newline(1):string("b", COLOR_LIGHTGREEN):string(": ") dc:newline(1):key('CUSTOM_B'):string(": ")
self.brush:render(dc) self.brush:render(dc)
dc:newline(1):string("p", COLOR_LIGHTGREEN):string(": ") dc:newline(1):key('CUSTOM_P'):string(": ")
self.paint:render(dc) self.paint:render(dc)
local paint = self.paint:get() local paint = self.paint:get()
@ -170,8 +170,8 @@ function LiquidsUI:onRenderBody(dc)
dc:newline() dc:newline()
if paint.liquid then if paint.liquid then
dc:newline(1):string("Amount: "..self.amount) dc:newline(1):string("Amount: "..self.amount)
dc:advance(1):string("("):string("-+", COLOR_LIGHTGREEN):string(")") dc:advance(1):string("("):key('SECONDSCROLL_UP'):key('SECONDSCROLL_DOWN'):string(")")
dc:newline(3):string("s", COLOR_LIGHTGREEN):string(": ") dc:newline(3):key('CUSTOM_S'):string(": ")
self.set:render(dc) self.set:render(dc)
else else
dc:advance(0,2) dc:advance(0,2)
@ -179,17 +179,17 @@ function LiquidsUI:onRenderBody(dc)
dc:newline() dc:newline()
if paint.flow then if paint.flow then
dc:newline(1):string("f", COLOR_LIGHTGREEN):string(": ") dc:newline(1):key('CUSTOM_F'):string(": ")
self.flow:render(dc) self.flow:render(dc)
dc:newline(1):string("r", COLOR_LIGHTGREEN):string(": ") dc:newline(1):key('CUSTOM_R'):string(": ")
self.permaflow:render(dc) self.permaflow:render(dc)
else else
dc:advance(0,2) dc:advance(0,2)
end end
dc:newline():newline(1):pen(COLOR_WHITE) dc:newline():newline(1):pen(COLOR_WHITE)
dc:string("Esc", COLOR_LIGHTGREEN):string(": Back, ") dc:key('LEAVESCREEN'):string(": Back, ")
dc:string("Enter", COLOR_LIGHTGREEN):string(": Paint") dc:key('SELECT'):string(": Paint")
end end
function ensure_blocks(cursor, size, cb) function ensure_blocks(cursor, size, cb)

@ -89,8 +89,8 @@ function MechanismList:onRenderBody(dc)
end end
dc:newline():newline(1):pen(COLOR_WHITE) dc:newline():newline(1):pen(COLOR_WHITE)
dc:string("Esc", COLOR_LIGHTGREEN):string(": Back, ") dc:key('LEAVESCREEN'):string(": Back, ")
dc:string("Enter", COLOR_LIGHTGREEN):string(": Switch") dc:key('SELECT'):string(": Switch")
end end
function MechanismList:changeSelected(delta) function MechanismList:changeSelected(delta)

@ -34,7 +34,8 @@ function PowerMeter:onRenderBody(dc)
dc:string("Excess power range:") dc:string("Excess power range:")
dc:newline(3):string("as", COLOR_LIGHTGREEN) dc:newline(3):key('BUILDING_TRIGGER_MIN_WATER_DOWN')
dc:key('BUILDING_TRIGGER_MIN_WATER_UP')
dc:string(": Min ") dc:string(": Min ")
if self.min_power <= 0 then if self.min_power <= 0 then
dc:string("(any)") dc:string("(any)")
@ -42,7 +43,8 @@ function PowerMeter:onRenderBody(dc)
dc:string(''..self.min_power) dc:string(''..self.min_power)
end end
dc:newline(3):string("zx", COLOR_LIGHTGREEN) dc:newline(3):key('BUILDING_TRIGGER_MAX_WATER_DOWN')
dc:key('BUILDING_TRIGGER_MAX_WATER_UP')
dc:string(": Max ") dc:string(": Max ")
if self.max_power < 0 then if self.max_power < 0 then
dc:string("(any)") dc:string("(any)")
@ -51,7 +53,7 @@ function PowerMeter:onRenderBody(dc)
end end
dc:newline():newline(1) dc:newline():newline(1)
dc:string("i",COLOR_LIGHTGREEN):string(": ") dc:key('CUSTOM_I'):string(": ")
if self.invert then if self.invert then
dc:string("Inverted") dc:string("Inverted")
else else

@ -185,10 +185,10 @@ function RoomList:onRenderBody(dc)
end end
dc:newline():newline(1):pen(COLOR_WHITE) dc:newline():newline(1):pen(COLOR_WHITE)
dc:string("Esc", COLOR_LIGHTGREEN):string(": Back") dc:key('LEAVESCREEN'):string(": Back")
if can_modify(sel_item) then if can_modify(sel_item) then
dc:string(", "):string("Enter", COLOR_LIGHTGREEN) dc:string(", "):key('SELECT')
if sel_item.obj.owner == sel_item.owner then if sel_item.obj.owner == sel_item.owner then
dc:string(": Unassign") dc:string(": Unassign")
else else

@ -204,14 +204,14 @@ function SiegeEngine:onRenderBody_main(dc)
dc:string("None (default)") dc:string("None (default)")
end end
dc:newline(3):string("r",COLOR_LIGHTGREEN):string(": Rectangle") dc:newline(3):key('CUSTOM_R'):string(": Rectangle")
if last_target_min then if last_target_min then
dc:string(", "):string("p",COLOR_LIGHTGREEN):string(": Paste") dc:string(", "):key('CUSTOM_P'):string(": Paste")
end end
dc:newline(3) dc:newline(3)
if target_min then if target_min then
dc:string("x",COLOR_LIGHTGREEN):string(": Clear, ") dc:key('CUSTOM_X'):string(": Clear, ")
dc:string("z",COLOR_LIGHTGREEN):string(": Zoom") dc:key('CUSTOM_Z'):string(": Zoom")
end end
dc:newline():newline(1) dc:newline():newline(1)
@ -219,7 +219,7 @@ function SiegeEngine:onRenderBody_main(dc)
dc:string("Uses ballista arrows") dc:string("Uses ballista arrows")
else else
local item = plugin.getAmmoItem(self.building) local item = plugin.getAmmoItem(self.building)
dc:string("u",COLOR_LIGHTGREEN):string(": Use ") dc:key('CUSTOM_U'):string(": Use ")
if item_choice_idx[item] then if item_choice_idx[item] then
dc:string(item_choices[item_choice_idx[item]].caption) dc:string(item_choices[item_choice_idx[item]].caption)
else else
@ -228,18 +228,20 @@ function SiegeEngine:onRenderBody_main(dc)
end end
dc:newline():newline(1) dc:newline():newline(1)
dc:string("t",COLOR_LIGHTGREEN):string(": Take from stockpile"):newline(3) dc:key('CUSTOM_T'):string(": Take from stockpile"):newline(3)
local links = plugin.getStockpileLinks(self.building) local links = plugin.getStockpileLinks(self.building)
local bottom = dc.height - 5 local bottom = dc.height - 5
if links then if links then
dc:string("d",COLOR_LIGHTGREEN):string(": Delete, ") dc:key('CUSTOM_D'):string(": Delete, ")
dc:string("o",COLOR_LIGHTGREEN):string(": Zoom"):newline() dc:key('CUSTOM_O'):string(": Zoom"):newline()
self:renderStockpiles(dc, links, bottom-2-dc:localY()) self:renderStockpiles(dc, links, bottom-2-dc:localY())
dc:newline():newline() dc:newline():newline()
end end
local prof = self.building:getWorkshopProfile() or {} local prof = self.building:getWorkshopProfile() or {}
dc:seek(1,math.max(dc:localY(),19)):string('ghjk',COLOR_LIGHTGREEN)dc:string(': ') dc:seek(1,math.max(dc:localY(),19))
dc:key('CUSTOM_G'):key('CUSTOM_H'):key('CUSTOM_J'):key('CUSTOM_K')
dc:string(': ')
dc:string(df.skill_rating.attrs[prof.min_level or 0].caption):string('-') dc:string(df.skill_rating.attrs[prof.min_level or 0].caption):string('-')
dc:string(df.skill_rating.attrs[math.min(LEGENDARY,prof.max_level or 3000)].caption) dc:string(df.skill_rating.attrs[math.min(LEGENDARY,prof.max_level or 3000)].caption)
dc:newline():newline() dc:newline():newline()
@ -357,7 +359,7 @@ function SiegeEngine:onRenderBody_aim(dc)
dc:newline(2):string('ERROR', COLOR_RED) dc:newline(2):string('ERROR', COLOR_RED)
end end
dc:newline():newline(1):string("Enter",COLOR_LIGHTGREEN) dc:newline():newline(1):key('SELECT')
if first then if first then
dc:string(": Finish rectangle") dc:string(": Finish rectangle")
else else
@ -367,7 +369,7 @@ function SiegeEngine:onRenderBody_aim(dc)
local target_min, target_max = plugin.getTargetArea(self.building) local target_min, target_max = plugin.getTargetArea(self.building)
if target_min then if target_min then
dc:newline(1):string("z",COLOR_LIGHTGREEN):string(": Zoom to current target") dc:newline(1):key('CUSTOM_Z'):string(": Zoom to current target")
end end
if first then if first then
@ -412,9 +414,9 @@ function SiegeEngine:onRenderBody_pile(dc)
if plugin.isLinkedToPile(self.building, sel) then if plugin.isLinkedToPile(self.building, sel) then
dc:string("Already taking from here"):newline():newline(2) dc:string("Already taking from here"):newline():newline(2)
dc:string("d", COLOR_LIGHTGREEN):string(": Delete link") dc:key('CUSTOM_D'):string(": Delete link")
else else
dc:string("Enter",COLOR_LIGHTGREEN):string(": Take from this pile") dc:key('SELECT'):string(": Take from this pile")
end end
elseif sel then elseif sel then
dc:string(utils.getBuildingName(sel), COLOR_DARKGREY) dc:string(utils.getBuildingName(sel), COLOR_DARKGREY)
@ -460,8 +462,8 @@ function SiegeEngine:onRenderBody(dc)
self.mode.render(dc) self.mode.render(dc)
dc:seek(1, math.max(dc:localY(), 21)):pen(COLOR_WHITE) dc:seek(1, math.max(dc:localY(), 21)):pen(COLOR_WHITE)
dc:string("ESC", COLOR_LIGHTGREEN):string(": Back, ") dc:key('LEAVESCREEN'):string(": Back, ")
dc:string("c", COLOR_LIGHTGREEN):string(": Recenter") dc:key('CUSTOM_C'):string(": Recenter")
end end
function SiegeEngine:onInput(keys) function SiegeEngine:onInput(keys)